package edu.sctu.zhu.dao;

import edu.sctu.zhu.bean.GoodsJson;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* Created by zhu on 2015/12/28.
*/
@Repository
public interface GoodsImageDao  extends CrudRepository<GoodsJson,Long> {
    @Query(value = "SELECT goods.*,image.url FROM goods JOIN image ON  image.image_user = ? AND goods.is_hot = ? AND goods.id = image.parent_id",nativeQuery = true)
    public List<GoodsJson> findHotGoods(String use, boolean isHot);

    @Query(value = "SELECT goods.*,image.url FROM goods JOIN image ON  image.image_user ='goodsIndex' AND goods.id = ? AND goods.id = image.parent_id",nativeQuery = true)
    public GoodsJson findGoods(Long id);

    @Query(value = "SELECT goods.*,image.url FROM goods JOIN image ON  image.image_user = ? AND goods.is_best = ? AND goods.id = image.parent_id",nativeQuery = true)
    public List<GoodsJson> findBestGoods(String use, boolean isHot);

    @Query(value = "SELECT goods.*,image.url FROM goods,image,collection WHERE  collection.fans_id = ? AND collection.goods_id=goods.id And image.image_user = 'goodsIndex' AND goods.id = image.parent_id",nativeQuery = true)
    public List<GoodsJson> findCollection(Long fans);

    @Query(value = "SELECT goods.*,image.url FROM goods JOIN image ON  image.image_user = ? AND goods.category_id = ? AND goods.id = image.parent_id",nativeQuery = true)
    public List<GoodsJson> findCategoryGoods(String use, Long id);

    @Query(value = "SELECT goods.*,image.url FROM goods JOIN image ON  image.image_user = ? AND goods.name LIKE ? AND goods.id = image.parent_id",nativeQuery = true)
    public List<GoodsJson> findSearchGoods(String use, String name);
}
